/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.knezevic.realestate.beans;

import com.knezevic.realestate.Advert;
import com.knezevic.realestate.Identifiable;
import com.knezevic.realestate.Member;
import com.knezevic.realestate.RealEstate;
import com.knezevic.realestate.TypeOfAdvert;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 *
 * @author Nemanja
 */
@Entity
public class AdvertBean implements Advert, Identifiable, Serializable{
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(targetEntity=MemberBean.class)
    private Member member;
    @OneToOne(targetEntity=RealEstateBean.class)
    private RealEstate realEstate;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;
    @Basic
    private TypeOfAdvert typeOfAdvert;

    @Basic
    private boolean confirmed;
    @Basic
    private String image;

    @Inject
    public AdvertBean() {
    }

    public AdvertBean(Member member, Date date, TypeOfAdvert typeOfAdvert, RealEstate realEstate,String image, boolean confirmed) {
        this.id = Long.MAX_VALUE-(long)(Math.random()*100000);
        this.member = member;
        this.date = date;
        this.typeOfAdvert = typeOfAdvert;
        this.realEstate = realEstate;
        this.image = image;
        this.confirmed = confirmed;
    }
    /**
     * @return the member
     */
    @Validate("required")
    public Member getMember() {
        return member;
    }

    /**
     * @param member the member to set
     */
    public void setMember(Member member) {
        this.member = member;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the typeOfAdvert
     */
    @Validate("required")
    public TypeOfAdvert getTypeOfAdvert() {
        return typeOfAdvert;
    }

    /**
     * @param typeOfAdvert the typeOfAdvert to set
     */
    public void setTypeOfAdvert(TypeOfAdvert typeOfAdvert) {
        this.typeOfAdvert = typeOfAdvert;
    }

    /**
     * @return the realEstate
     */
    @Validate("required")
    public RealEstate getRealEstate() {
        return realEstate;
    }

    /**
     * @param realEstate the realEstate to set
     */
    public void setRealEstate(RealEstate realEstate) {
        this.realEstate = realEstate;
    }

    /**
     * @return the confirmed
     */
    public boolean isConfirmed() {
        return confirmed;
    }

    /**
     * @param confirmed the confirmed to set
     */
    public void setConfirmed(boolean confirmed) {
        this.confirmed = confirmed;
    }
    @Override
    public String toString() {
        return super.toString();
    }

    @Override
    public boolean equals(Object obj) {
        AdvertBean a = (AdvertBean) obj;
        if(this.getID()==a.getID())
            return true;
        return false;
    }

    /**
     * @return the image
     */
    public String getImage() {
        return image;
    }

    /**
     * @param image the image to set
     */
    public void setImage(String image) {
        this.image = image;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    public long getID() {
        return id;
    }
  

}
